<?php
require_once $_SERVER['DOCUMENT_ROOT'].'/home/config.php';

$array_return = array();
$array_return['status'] = 0;
$array_return['html'] = '';

$more_id = getValue('more_id','int','POST',0);
$more_type = getValue('more_type','str','POST','',2);
$more_page = getValue('more_page','int','POST',0);

if($more_id == 0 || $more_type == '' || $more_page == 0) {
   $array_return['status'] = 2;
}else {
   $start = $more_page*10;
   $list_comments = db_array('SELECT * FROM comments WHERE com_post_id = '.$more_id.' AND com_type = "'.$more_type.'" ORDER BY com_id DESC LIMIT '.$start.',10');
   $html = '';
   foreach($list_comments as $comment) {
      $html .= '<div class="comment_item">
                  <img src="/themes/img/avatar_guest.jpg" alt="avatar guest comment" />
                  <p class="cmt_name"><strong>'.$comment['com_name'].'</strong></p>
                  <p class="cmt_content">'.$comment['com_content'].'</p>
                  <p class="cmt_meta">
                     <span class="cmt_reply" data-id="'.$comment['com_id'].'">Trả lời</span>
                     <span class="cmt_like" data-id="'.$comment['com_id'].'" data-type="comment" data-like="'.$comment['com_like'].'">Thích <i class="icon_like"></i> <span>'.$comment['com_like'].'</span></span>
                     <span class="cmt_date">'.getTodayYesterdayString($comment['com_date']).'</span>
                  </p>
               </div>';
      $list_reply = db_array('SELECT * FROM comments_reply WHERE rep_comment_id = '.$comment['com_id'].' LIMIT 3');
      foreach($list_reply as $reply) {
         $html .= '<div class="reply_item">
                     <img src="/themes/img/avatar_guest.jpg" alt="avatar guest comment" />
                     <p class="cmt_name"><strong>'.$reply['rep_name'].'</strong></p>
                     <p class="cmt_content">'.$reply['rep_content'].'</p>
                     <p class="cmt_meta">
                        <span class="cmt_like" data-id="'.$reply['rep_id'].'" data-type="reply" data-like="'.$reply['rep_like'].'">Thích <i class="icon_like"></i> <span>'.$reply['rep_like'].'</span></span>
                        <span class="cmt_date">'.getTodayYesterdayString($reply['rep_date']).'</span>
                     </p>
                  </div>';
      }
   }
   if(count($list_comments) == 10) {
      $array_return['status'] = 1;
   }else {
      $array_return['status'] = 2;
   }
   $array_return['html'] = $html;
}

die(json_encode($array_return));
?>